#ifndef READIN_CC
#define READIN_CC

#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <list>
#include "Process.h"
#include "Scheduler.h"

using namespace std;

class ReadIn{
protected: 
	
	list<string>* numList;
	list<int>* formattedProcesses;
	list<Process>* processList;
	int userProcess;
	int numQueues;
	int numProc;
	int numQuant;
	int ageTime;
	
public:
	ReadIn(int userProc, int numQueue, int numProcessors, int numQuantums, int agingTime){
		userProcess = userProc;
		numQueues = numQueue;
		numProc = numProcessors;
		numQuant = numQuantums;
		ageTime = agingTime;
		addProcesses();
	
	}
	void addProcesses(){
		char fileName[30];
		cout << "Insert File Name -> " << endl;
		cin >> fileName;

		

		// read in commands 
		
		ifstream actions(fileName); 
		string temp("");
		formattedProcesses = new list<int>();
		processList = new list<Process>();
		numList = new list<string>();
			while(!actions.eof()){
				getline(actions, temp);
				numList->push_back(temp);
			}
		actions.close();
		// parse through the list and add each number separated by spaces to formatted actions list
		list<string>::iterator it;
		for(it = numList->begin(); it != numList->end(); it++){
			stringstream ss(*it);
			string temp;
			while(ss>>temp){
				int num = atoi(temp.c_str());
				formattedProcesses->push_back(num);
			}
		}
		delete numList;
		int PID =0;
		int arrival = 0;
		int burst=0;
		int priority=0;
		list<int>::iterator i = formattedProcesses->begin();


		while(i != formattedProcesses->end()){

			PID =*i;
			//formattedProcesses->pop_front();
			cout<<"PID: "<< PID<<endl;
			i++;
			burst = *i;
			cout<<"Burst Time: " <<burst<<endl;
			i++;
			arrival = *i;
			cout<<"Arrival: "<< arrival<<endl;
			//formattedProcesses->pop_front();
			i++;

			if (userProcess == 3){
				priority = *i;
				cout<<"Priority: "<<priority<<endl;
				i++;
			}
			Process proc(PID,arrival, burst, priority, 1, 0,0);
			// create a list of processes
			processList->push_back(proc);

		}
		Scheduler sched(processList, userProcess, numQueues, numProc,numQuant, ageTime);
		
	
	}

	
};
#endif

